//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    huiyuan: [
      { text: '0', text1: '心情' },
      { text: '0', text1: '关注' },
      { text: '0', text1: '粉丝' },
      { text: '0', text1: '招呼' },
      { text: '0', text1: '留言' }
    ],
    navArrs: [
      { image: '../../images/personal/xiangce.png', text: '我的相册' },
      { image: '../../images/personal/shipin.png', text: '我的视频' },
      { image: '../../images/personal/huodong.png', text: '我的活动' },
      { image: '../../images/personal/aiixnditu.png', text: '爱情地图' },
      { image: '../../images/personal/mima.png', text: '修改密码' },
      { image: '', text: '' }
    ],
    navcon: [
      { image: '../../images/personal/supei.png', text: '每日速配' },
      { image: '../../images/personal/qiandao.png', text: '每日签到' },
      { image: '../../images/personal/bianji.png', text: '个人编辑' },
      { image: '../../images/personal/zeoutianjian.png', text: '择偶条件' },
      { image: '../../images/personal/yanjing.png', text: '我看过谁' },
      { image: '../../images/personal/liuyan.png', text: '我的留言' },
      { image: '../../images/personal/zhaohu.png', text: '我的招呼' },
      { image: '../../images/personal/xinxi.png', text: '站内信息' },
      { image: '../../images/personal/heimingdan.png', text: '黑名单' }
    ],
    renderObj: {},
    member: {},
    registerTime: '',
    lastLoginTime: '',
    userHeadImg: '',
    userLevelImg: '',
    reloadFlag: false//刷新页面标识
  },
  onShow: function () {
    if (this.data.reloadFlag) {
      var _this = this;
      var userid = app.globalData.userid;
      if (!userid) {
        var openid = wx.getStorageSync('openid');
        if (!openid) {
          app.wxLogin().then(function (v) {//
            if (v) {
              app.ifLogin().then(function () {
                _this.initPage();
              })
            }
          })
        } else {
          app.getUserInfoSyn().then(function () {
            _this.initPage();
          })
        }
      } else {
        _this.initPage();
      }
    }
  },
  //事件处理函数
  onLoad: function (opt) {
    var _this = this;
    var userid = app.globalData.userid;
    if (!userid) {
      var openid = wx.getStorageSync('openid');
      if (!openid) {
        app.wxLogin().then(function (v) {//
          if (v) {
            app.ifLogin().then(function () {
              _this.initPage();
            })
          }
        })
      } else {
        app.getUserInfoSyn().then(function () {
          _this.initPage();
        })
      }
    } else {
      _this.initPage();
    }
  },
  // <!--我的相册，我的视频，我的活动，爱情地图，修改密码-- >
  goSomePage: function (e) {
    console.log(e)
    if (e.currentTarget.dataset.index == 0) {
      wx.navigateTo({
        url: '../../pages/personalPictures/personalPictures',
      })
    } else if (e.currentTarget.dataset.index == 1) {
      wx.navigateTo({
        url: '../../pages/personalVideos/personalVideos',
      })
    } else if (e.currentTarget.dataset.index == 2) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=1&type=2',
      });
    } else if (e.currentTarget.dataset.index == 3) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=2&type=4',
      })
    } else if (e.currentTarget.dataset.index == 4) {
      wx.navigateTo({
        url: '../../pages/personalPwdEdit/personalPwdEdit?page=2&type=2',
      })
    }
    // 爱情地图
    else if (e.currentTarget.dataset.index == 3) {
      wx.navigateTo({
        url: '../../pages/loveMap/loveMap',
      })
    }
  },
  gomhomePage: function (e) {
    // 每日速配
    if (e.currentTarget.dataset.index == 0) {
      wx.navigateTo({
        url: '../../pages/speedDating/speedDating',
      })
    }
    // 每日签到
    else if (e.currentTarget.dataset.index == 1) {
      wx.navigateTo({
        url: '../../pages/dailyAttendance/dailyAttendance',
      })
    }
    // 个人编辑
    else if (e.currentTarget.dataset.index == 2) {
      wx.navigateTo({
        url: '../../pages/personalInfoEdit/personalInfoEdit',
      })
    }
    // 择偶条件
    else if (e.currentTarget.dataset.index == 3) {
      wx.navigateTo({
        url: '../../pages/mateCondition/mateCondition',
      })
    }
    // 我看过谁
    else if (e.currentTarget.dataset.index == 4) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=1&type=3',
      });
    }
    // 我的留言
    else if (e.currentTarget.dataset.index == 5) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=2&type=1',
      });
    }
    // 我的招呼
    else if (e.currentTarget.dataset.index == 6) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=2&type=3',
      });
    }
    // 站内信息
    else if (e.currentTarget.dataset.index == 7) {
      wx.navigateTo({
        url: '../../pages/myMsg/myMsg',
      })
    }
    // 黑名单
    else if (e.currentTarget.dataset.index == 8) {
      wx.navigateTo({
        url: '../../pages/personalBlackList/personalBlackList',
      })
    }
  },
  initPage: function (opt) {
    app.getUserInfo({ "openId": wx.getStorageSync('openid') });
    var userInfo = wx.getStorageSync("userInfo");
    this.setData({
      renderObj: userInfo,
      member: wx.getStorageSync("userInfoEnctype"),
      huiyuan: [
        { text: userInfo.member.mood, text1: '心情' },
        { text: userInfo.member.buzz, text1: '关注' },
        { text: userInfo.member.fans, text1: '粉丝' },
        { text: userInfo.member.inbox, text1: '招呼' },
        { text: userInfo.member.greeted, text1: '留言' }
      ],
      registerTime: userInfo.member.registerTime.split(' ')[0],
      lastLoginTime: userInfo.member.signinTime.split(' ')[0],
      userHeadImg: app.globalData.picServer+ userInfo.member.headImg,
      userLevelImg: app.globalData.picServer + '/www/images/hy' + userInfo.member.hydj + '.png',
    });
  },
  noLongerSingleDog: function () {//我已脱单
    wx.showLoading({
      title: '数据加载中....',
      mask: true
    })
    var _this = this;
    app.doReq(app.globalData.SERVICE.USERCENTER.MEMBER_UPTZ, {
      id: app.globalData.userid,
      type: 1
    }, 'get', function (res) {
      let data = res.data
      if (data.type === 'SUCCESS') {
        app.getUserInfoSyn({ "openId": wx.getStorageSync('openid') }).then(function () {

          if (_this.data.renderObj.member.sfgb == 0) {
            wx.hideLoading();
            wx.showToast({
              title: '恭喜您脱单成功！',
              icon: 'suceess',
              success: function () {
                _this.initPage();
              }
            })
          } else {
            wx.showToast({
              title: '我们将继续为您服务！',
              icon: 'suceess',
              success: function () {
                _this.initPage();
              }
            })
          }
        })
      }
    });
  },
  closeNotice: function () {//关闭通知
    wx.showLoading({
      title: '数据加载中....',
      mask: true
    })
    var _this = this;
    app.doReq(app.globalData.SERVICE.USERCENTER.MEMBER_UPTZ, {
      id: app.globalData.userid,
      type: 2
    }, 'get', function (res) {
      let data = res.data
      if (data.type === 'SUCCESS') {
        app.getUserInfoSyn({ "openId": wx.getStorageSync('openid') }).then(function () {

          if (_this.data.renderObj.member.sftz == 0) {
            wx.hideLoading();
            wx.showToast({
              title: '您已关闭通知！',
              icon: 'suceess',
              success: function () {
                _this.initPage();
              }
            })
          } else {
            wx.showToast({
              title: '您已开启通知！',
              icon: 'suceess',
              success: function () {
                _this.initPage();
              }
            })
          }
        })
      }
    });
  },
  goBarPage: function (e) {
    if (e.currentTarget.dataset.index == 0) {
      wx.navigateTo({
        url: '../../pages/personalMood/personalMood',
      })
    } else if (e.currentTarget.dataset.index == 1) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=1&type=1',
      });
    } else if (e.currentTarget.dataset.index == 2) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=1&type=2',
      });
    } else if (e.currentTarget.dataset.index == 3) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=2&type=4',
      })
    } else if (e.currentTarget.dataset.index == 4) {
      wx.navigateTo({
        url: '../../pages/userList/userList?page=2&type=2',
      })
    }
    // 爱情地图
    else if (e.currentTarget.dataset.index == 3) {
      wx.navigateTo({
        url: '../../pages/loveMap/loveMap',
      })
    }
  }
})
